import { Table, Space } from 'antd';
import React from 'react';
import Edit from './ModalEdit'
import http from '../../../services/http';

const columns = [
  {
    title: '标准指标ID',
    dataIndex: 'stan_unild',
  },
  {
    title: '标准指标名称',
    dataIndex: 'stan_name',
  },
  {
    title: '指标单位',
    dataIndex: 'stan_standardUnit',
  },
  {
    title: '参考上限',
    dataIndex: 'stan_upper',
  },
  {
    title: '参考下限',
    dataIndex: 'stan_lower',
  },
  {
    title: '正常提示',
    dataIndex: 'stan_normalMsg',
  },
  {
    title: '偏高提示',
    dataIndex: 'stan_upMsg',
  },
  {
    title: '偏低提示',
    dataIndex: 'stan_lowerMsg',
  },
  {
    title: '是否比对',
    dataIndex: 'stan_contrast',
  },
  {
    title: '操作',
    dataIndex: '操作',

  }
];

const data = [];

class App extends React.Component {
  state = {
    selectedRowKeys: [],
    loading: false,
    tableData: [],
    id: '',
    data: []

  };

  tableFor = () => {
    let arr=[];
    for (let i = 0; i < this.state.tableData.length; i++) {
      arr.push({
        key: this.state.tableData[i].stan_id,
        stan_unild: this.state.tableData[i].stan_unild,
        stan_name: this.state.tableData[i].stan_name,
        stan_standardUnit: this.state.tableData[i].stan_standardUnit,
        stan_upper: this.state.tableData[i].stan_upper,
        stan_lower: this.state.tableData[i].stan_lower,
        stan_normalMsg: this.state.tableData[i].stan_normalMsg,
        stan_upMsg: this.state.tableData[i].stan_upMsg,
        stan_lowerMsg: this.state.tableData[i].stan_lowerMsg,
        stan_contrast: this.state.tableData[i].stan_contrast,
        操作: <Space style={{ width: 150 }} size="middle"><Edit edit={this.state.tableData[i].stan_id}></Edit> <a onClick={this.del.bind(this, i)}>删除</a></Space>
      })
    }
    this.setState({
      data:arr
    })
  }

  getCon = () => {
    http({
      url: '/getstandard'
    }).then((res) => {
      console.log(1212,res,this.state.tableData);
      this.setState({
        tableData:res
      })
      console.log(12123,this.state.tableData)
      this.tableFor();
    })
  }

  

  del = (i) => {
    this.state.sel = false;
    console.log(this.state.tableData[i].stan_id);
    http({
      url: '/delstandard',
      method: 'post',
      data: {
        stan_id: this.state.tableData[i].stan_id
      }
    }).then((res) => {
      if (res.status == 200) {
        console.log('删除成功了！');
        this.getCon();
      }
    })
  }

  componentDidMount() {
    this.getCon();
  }

  componentWillUnmount(){
    this.setState = (state,callback)=>{
      return
    }
  }

  start = () => {
    console.log('111111', this.state.tableData[this.state.selectedRowKeys].stan_id)
    this.setState({ loading: true });
    // ajax request after empty completing
    setTimeout(() => {
      this.setState({
        selectedRowKeys: [],
        loading: false,
      });
    }, 1000);
    //console.log(this.state.selectedRowKeys)
  };

  onSelectChange = selectedRowKeys => {
    //console.log('selectedRowKeys changed: ', selectedRowKeys);
    this.setState({ selectedRowKeys });
  };

  render() {
    const { loading, selectedRowKeys } = this.state;
    const rowSelection = {
      selectedRowKeys,
      onChange: this.onSelectChange,
    };
    const hasSelected = selectedRowKeys.length > 0;
    return (
      <div className="tablebox">
        <div style={{ marginBottom: 16 }}>
          {/* <Button type="primary" onClick={this.start} disabled={!hasSelected} loading={loading}>
              删除
            </Button> */}
          {/* <span style={{ marginLeft: 8 }}>
              {hasSelected ? `已选中 ${selectedRowKeys.length} 项` : ''}
            </span> */}
        </div>
        <Table rowSelection={rowSelection} columns={columns} dataSource={this.state.data} pagination={true} />
      </div>
    );
  }
}

export default App;